<?php

namespace App\Http\Controllers\Admin;

use App\Models\SystemConfig;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RechargeController extends Controller
{
    public function index(SystemConfig $sysCfgModel)
    {
        $data['config_arr'] = [
            'recharge_money' => filter_empty($sysCfgModel::getConfValByConfKey('recharge_money'),'conf_val') , //充值优惠满多少金额
            'gift_money'     => filter_empty($sysCfgModel::getConfValByConfKey('gift_money'),'conf_val') ,     //充值满足recharge_money数量后赠送多少金额
            'recharge_limit' => filter_empty($sysCfgModel::getConfValByConfKey('recharge_limit'),'conf_val'), //充值优惠次数限制
            'gift_limit'     => filter_empty($sysCfgModel::getConfValByConfKey('gift_limit'),'conf_val'),     //赠送优惠上限
        ];
        return view('admin.recharge.index',$data);
    }

    public function save(Request $request,SystemConfig $sysCfgModel)
    {
        $post_data = $request -> input('Recharge');
        foreach($post_data as $key => $val)
        {
            $val = isset($val)  ? $val : '';
            $sysCfgModel::modifyValByConfKey($key,$val);
        }
        return redirect()->back()->with('success','保存成功');
    }
}
